package com.fy.fyspace.model.dto.hotness;

import lombok.Data;

import java.time.LocalDateTime;

/**
 * 图片热度数据传输对象
 * 设计模式：建造者模式，用于构建热度计算所需的数据
 * 
 * @author fwq
 * @since 2024-12-19
 */
@Data
public class PictureHotnessData {
    
    /**
     * 图片ID
     */
    private Long pictureId;
    
    /**
     * 下载次数
     */
    private Integer downloadCount;
    
    /**
     * 点赞次数
     */
    private Integer likeCount;
    
    /**
     * 收藏次数
     */
    private Integer favoriteCount;
    
    /**
     * 创建时间
     */
    private LocalDateTime createTime;
    
    /**
     * 分类
     */
    private String category;
    
    /**
     * 距离创建的天数
     */
    private Integer daysSinceCreation;
    
    /**
     * 私有构造函数，强制使用建造者
     */
    private PictureHotnessData(Long pictureId, Integer downloadCount, Integer likeCount, 
                              Integer favoriteCount, LocalDateTime createTime, String category, 
                              Integer daysSinceCreation) {
        this.pictureId = pictureId;
        this.downloadCount = downloadCount;
        this.likeCount = likeCount;
        this.favoriteCount = favoriteCount;
        this.createTime = createTime;
        this.category = category;
        this.daysSinceCreation = daysSinceCreation;
    }
    
    /**
     * 建造者类
     * 设计模式：建造者模式，提供流式API构建对象
     */
    public static class Builder {
        private Long pictureId;
        private Integer downloadCount = 0;
        private Integer likeCount = 0;
        private Integer favoriteCount = 0;
        private LocalDateTime createTime;
        private String category;
        private Integer daysSinceCreation;
        
        public Builder pictureId(Long pictureId) {
            this.pictureId = pictureId;
            return this;
        }
        
        public Builder downloadCount(Integer downloadCount) {
            this.downloadCount = downloadCount != null ? downloadCount : 0;
            return this;
        }
        
        public Builder likeCount(Integer likeCount) {
            this.likeCount = likeCount != null ? likeCount : 0;
            return this;
        }
        
        public Builder favoriteCount(Integer favoriteCount) {
            this.favoriteCount = favoriteCount != null ? favoriteCount : 0;
            return this;
        }
        
        public Builder category(String category) {
            this.category = category;
            return this;
        }
        
        public Builder createTime(LocalDateTime createTime) {
            this.createTime = createTime;
            if (createTime != null) {
                this.daysSinceCreation = (int) java.time.temporal.ChronoUnit.DAYS.between(createTime, LocalDateTime.now());
            }
            return this;
        }
        
        public PictureHotnessData build() {
            if (pictureId == null) {
                throw new IllegalArgumentException("图片ID不能为空");
            }
            if (createTime == null) {
                throw new IllegalArgumentException("创建时间不能为空");
            }
            return new PictureHotnessData(pictureId, downloadCount, likeCount, favoriteCount, 
                                        createTime, category, daysSinceCreation);
        }
    }
    
    /**
     * 静态工厂方法，创建建造者
     */
    public static Builder builder() {
        return new Builder();
    }
} 